﻿/*
 * Autore: Artur Tolstenco
 */

using System.Globalization;
using System.Windows.Controls;
using RecipesManager.Data;

namespace RecipesManager.MainControls.GuestSubControls
{
    /// <summary>
    /// Interaction logic for ViewRecipesStatsWindow.xaml
    /// </summary>
    public partial class ViewRecipesStatsWindow
    {
        readonly IRecipeStats _recipesStats;
        public ViewRecipesStatsWindow(IRecipeStats rs)
        {
            InitializeComponent();

            _recipesStats = rs;

            foreach (var recipesStat in _recipesStats)
                cb_recipes.Items.Add(recipesStat.Name);

            if (cb_recipes.Items.Count > 0)
                cb_recipes.SelectedIndex = 0;
        }

        private void Cb_Recipes_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectedItem = cb_recipes.SelectedItem as string;

            if (selectedItem == null)
            {
                tb_numberTimes.Text = "";
                dp_lastTime.Value = null;
                return;
            }

            tb_numberTimes.Text = _recipesStats[selectedItem].Count.ToString(CultureInfo.InvariantCulture);
            dp_lastTime.Value = _recipesStats[selectedItem].LastServed;
        }

    }
}
